/**
 * ************************************************************************
 *
 * @file    Version.c
 * @brief   版本控制
 * @author  负号科技(fuhaokj@foxmail.com)
 * @version 0.1
 * @date    2023-08-25
 *
 * ************************************************************************
 *   __       _                 _    _
 *  / _|     | |               | |  (_)
 * | |_ _   _| |__   __ _  ___ | | ___
 * |  _| | | | '_ \ / _` |/ _ \| |/ / |
 * | | | |_| | | | | (_| | (_) |   <| |
 * |_|  \__,_|_| |_|\__,_|\___/|_|\_\ |
 *                                 _/ |
 *                                |__/
 *
 * @copyright Copyright (c) 2023 负号科技
 * For study and research only, no reprinting
 * ************************************************************************
 */
#include "Version.h"
#include <stdio.h>
#include "config.h"

char rc_data[][9] = {"Base", "Alpha", "Beta", "RC", "Release", "standard", "full", "lts", "ultimate", "demo", "enhance", "free", "upgrade"};

/**
 * @brief   打印版本号
 * @date    2023-08-28
 *
 */
void PrintVersionInformation(void)
{
   BUILD_TIME_TYPE_DEF Build_Time;
   msg_version_char pv = {PROJECT_NAME};

   if ((uint8_t)APP_VERSION > 13)
   {
      return;
   }
   ObtainBuildTime(&Build_Time);
   LOG_info("%s_V%d.%d.%d.%d%02d%02d_%s", pv.project, (APP_VERSION >> 24), (uint8_t)(APP_VERSION >> 16), (uint8_t)(APP_VERSION >> 8),
            Build_Time.year, Build_Time.month, Build_Time.day, rc_data[(uint8_t)APP_VERSION]);
}

/**
 * @brief   返回版本号字符
 * @param   str     传入存放数据的空间
 * @return  char*   返回存放数据的空间
 * @date    2023-08-29
 *
 */
char *VersionPrintParameters(char *str)
{
   // if (str == NULL)
   // {
   //    return 0;
   // }

   BUILD_TIME_TYPE_DEF Build_Time;
   msg_version_char pv = {PROJECT_NAME};

   if ((uint8_t)APP_VERSION > 13)
   {
      return 0;
   }

   ObtainBuildTime(&Build_Time);
   sprintf(str, "%s_V%d.%d.%d.%d%02d%02d_%s", pv.project, (APP_VERSION >> 24), (uint8_t)(APP_VERSION >> 16), (uint8_t)(APP_VERSION >> 8), Build_Time.year, Build_Time.month, Build_Time.day, rc_data[(uint8_t)APP_VERSION]);

   return str;
}

/**
 * @brief   获取版本号BIN
 * @param   str         传入存放数据的空间
 * @return  msg_version_bin_def* 
 * @date    2023-09-01
 * 
 */
msg_version_bin *VersionParametersBIN(msg_version_bin *str)
{
   // if (str == NULL)
   // {
   //    return 0;
   // }

   BUILD_TIME_TYPE_DEF Build_Time;

   if ((uint8_t)APP_VERSION > 13)
   {
      return 0;
   }

   ObtainBuildTime(&Build_Time);

   str->version = APP_VERSION;
   str->year = Build_Time.year;
   str->month = (uint8_t)Build_Time.month;
   str->day = (uint8_t)Build_Time.day;

   return str;
}
